using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
using System.Threading.Tasks;
using bitzhuwei.Compiler;

namespace bitzhuwei.AnsiCFormat {
    /// <summary>
    /// extracted info from syntax tree(<see cref="LRNode"/>).
    /// </summary>
    public partial class translation_unit : IFullFormatter {
        // [-1]=translation_unit' : translation_unit ;
        // dumped by ExternalExtractor
        internal readonly Vntranslation_unit @final;

        internal translation_unit(Vntranslation_unit final) {
            this.@final = final;
        }

        public TokenRange Scope => this.final.Scope;

        public void Format(TextWriter writer, FormatContext context) {
            throw new NotImplementedException();
        }

        public void FullFormat(BlankConfig preConfig, TextWriter writer, FormatContext context) {
            {
                //context.PrintComment(context.tokens[0], this._translationUnit, writer);
                var start = 0;
                var end = this.final.Scope.start - 1;
                var switches1 = new BlankConfig(inlineBlank: 1, forceNewline: false);
                context.PrintCommentsBetween(start, end, switches1, writer);
            }
            this.final.FullFormat(preConfig, writer, context);
            {
                //context.PrintComment(this._translationUnit, context.tokens[context.tokens.Count - 1], writer);
                var start = this.final.Scope.end + 1;
                var end = context.tokens.Count - 1;
                var switches1 = new BlankConfig(inlineBlank: 1, forceNewline: false);
                context.PrintCommentsBetween(start, end, switches1, writer);
            }
        }

        public IEnumerable<string> YieldTokens(TextWriter writer, FormatContext context) {
            throw new NotImplementedException();
        }
    }
}
